package com.qf.controller;

import com.qf.constans.ResultCode;
import com.qf.dto.R;
import com.qf.exceptions.AddDataException;
import com.qf.pojo.Categories;
import com.qf.service.ICategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoriesController {
    private ICategoriesService categoriesService;
    @Autowired
    public void setCategoriesService(ICategoriesService categoriesService) {
        this.categoriesService = categoriesService;
    }
    @PostMapping("/category")
    public R addCategori(@RequestBody Categories categories){
        categoriesService.addCategories(categories);
        return R.setOk(null);
    }

    @PostMapping("/newcategory/{categoryName}")
    public R addCategori(@PathVariable String categoryName){

        if(categoryName==null||categoryName.equals("")){
            throw new AddDataException("数据不完整", ResultCode.NULL_DATA);
        }
        categoriesService.addCategorie(categoryName);
        return R.setOk(null);
    }


}
